package com.kehutong.charge.admin;

import com.kehutong.charge.entity.ReceiptManages;
import com.kehutong.charge.service.ReceiptManagesService;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

/**
 * @program: kht
 * @description: 票据管理
 * @author: jian Ye
 * @create: 2021/8/3
 **/
@MvcAction
@ReqMapping("/admin/pay/charge/bill/receipt")
public class ReceiptManagesController {

    @Inject
    ReceiptManagesService receiptService;




    @ReqMapping("/page")
    @HasPermission("crm:charge:receipt:view")
    public Object page(JSONObject jsonObject) {
        return receiptService.findPage(jsonObject);
    }


    @ReqMapping("/list")
    @HasPermission("crm:charge:receipt:view")
    public Object list(JSONObject jsonObject) {
        return receiptService.findList(jsonObject);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:charge:receipt:edit")
    @ReqMapping("/save")
    public Object save(ReceiptManages entity, Token token){
        return receiptService.save(entity,token);
    }


    @Bean(copy=true)
    @HasPermission("crm:charge:receipt:edit")
    @ReqMapping("/update")
    public Object update(ReceiptManages entity) throws Exception {
        return receiptService.update(entity);
    }


    @HasPermission("crm:charge:receipt:edit")
    @ReqMapping("/delete")
    public Object delete(ReceiptManages entity) {
        return receiptService.deleteById(entity.getId());
    }


    @ReqMapping("/setStatus")
    @HasPermission("crm:charge:receipt:edit")
    public Object setStatus(ReceiptManages entity) throws Exception {
        entity.setStatus(!entity.isStatus());
        receiptService.update(entity);
        return Result.success();
    }


    @ReqMapping("/get")
    public Object get(ReceiptManages entity) {
        return Result.success(entity);
    }


    /**
     * 获取票据和缴费单信息列表
     * @param jsonObject
     * @return
     */
    @ReqMapping("/info/list")
    @HasPermission("crm:charge:receipt:view")
    public Object findReceiptAndInvoice(JSONObject jsonObject) {
        return receiptService.findReceiptAndInvoice(jsonObject);
    }

}
